package com.banshuibao.bsb_android.fragment;


import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class VideoFragment extends BaseFragment {

    private FragmentManager manager;

    // private RadioGroup radioGroup;

    private MediaListFragment mediaListFragment;

    //private ClassListFragment classListFragment;

    //private int type;


    public VideoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_video, container, false);
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        view.findViewById(R.id.back_iv).setVisibility(View.GONE);
        ((TextView) view.findViewById(R.id.title_text)).setText("财税课堂");
//        ImageView share = view.findViewById(R.id.share);
//        share.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                ShareUtil.showShare(getActivity(), Constants.Url.VIDEO, "","", null);
//            }
//        });

        //       ImageView record = view.findViewById(R.id.record);
//        record.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                IntentManager.goBuyMediaListActivity(getActivity());
//            }
//        });
        // radioGroup = view.findViewById(R.id.rg);

        manager = getChildFragmentManager();

     /*   radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == type)
                    return;
                hideFragment(mediaListFragment, classListFragment);
                FragmentTransaction transaction = manager.beginTransaction();
                switch (i) {
                    case R.id.title1:
                        if (mediaListFragment == null) {
                            mediaListFragment = new MediaListFragment();
                            transaction.add(R.id.fragment, mediaListFragment);
                        } else
                            transaction.show(mediaListFragment);
                        break;
                    case R.id.title2:
                        if (classListFragment == null) {
                            classListFragment = new ClassListFragment();
                            transaction.add(R.id.fragment, classListFragment);
                        } else
                            transaction.show(classListFragment);
                        break;
                }
                transaction.commit();
                type = i;
            }
        });
        radioGroup.check(R.id.title1);*/
        FragmentTransaction transaction = manager.beginTransaction();
        mediaListFragment = new MediaListFragment();
        transaction.add(R.id.fragment, mediaListFragment).commit();
    }

    private void hideFragment(Fragment... fragments) {
        for (Fragment fragment : fragments) {
            if (fragment != null)
                manager.beginTransaction().hide(fragment).commit();
        }
    }
}
